package com.lucian.ge.controller.shopportal;

import com.lucian.ge.auth.controller.GetAuthController;
import com.lucian.ge.service.shop.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.lucian.ge.comman.model.ResultMap;

import java.util.Random;


/**
 * Created by Lucicol on 2019/7/9.
 */
@Api(value = "OrderController", description = "order-订单接口")

@RestController
@RequestMapping("/order")
public class OrderController {
    private final ResultMap resultMap;
    @Autowired
    public OrderController(ResultMap resultMap) {
        this.resultMap = resultMap;
    }

    @Autowired(required=false)
    private OrderService orderService;

    @ApiOperation(value="创建订单", notes="")

    @ApiImplicitParams({
            @ApiImplicitParam(paramType="header", name = "token", value = "token", required = false, dataType = "String")
    })
    @GetMapping("/create")
    @ResponseBody
    public ResultMap create(@RequestHeader String token,
                            @RequestParam(value = "userid") Integer userId,
                            @RequestParam(value = "shippingId") Integer shippingId){
        if (!GetAuthController.getUserAuth(token).equals("普通注册用户验证通过")) {
            return resultMap.success().code(301).message(GetAuthController.getUserAuth(token)).token("").res("").data(null);
        }
        System.out.println("11111");

        orderService.create(userId, shippingId);
        System.out.println("222222222");
        return resultMap.success().code(200).message("订单创建成功").token("").res("").data(null);
    }

}
